package cn.arikeky.controller;

import cn.arikeky.basic.util.AjaxResult;
import cn.arikeky.basic.util.PageList;
import cn.arikeky.domain.User;
import cn.arikeky.query.UserQuery;
import cn.arikeky.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    // 修改 添加
    @PutMapping
    public AjaxResult addAndUpdate(@RequestBody User user){
        if (null == user.getUserId()){
            userService.add(user);
        } else {
            userService.update(user);
        }
        return  AjaxResult.me().success();
    }

    // 删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        userService.delete(id);
        return  AjaxResult.me().success();
    }

    // 查询所有
    @GetMapping
    public List<User> findAll(){
        return userService.findUserAll();
    }

    // 分页查询
    @PostMapping
    public PageList<User> queryById(@RequestBody UserQuery userQuery){
        System.out.println(111);
        return userService.queryByPage(userQuery);
    }


}
